package com.easemob.server.example;

import com.easemob.server.example.api.ChatGroupAPI;
import com.easemob.server.example.comm.ClientContext;
import com.easemob.server.example.comm.EasemobRestAPIFactory;
import com.easemob.server.example.comm.wrapper.ResponseWrapper;

public class Main {

	public static void main(String[] args) throws Exception {
		EasemobRestAPIFactory factory = ClientContext.getInstance().init(ClientContext.INIT_FROM_PROPERTIES).getAPIFactory();
		
		//IMUserAPI user = (IMUserAPI)factory.newInstance(EasemobRestAPIFactory.USER_CLASS);
		//System.out.println(user);
		
		ChatGroupAPI group = (ChatGroupAPI)factory.newInstance(EasemobRestAPIFactory.CHATGROUP_CLASS);
		
		/*ChatGroupBody payload = new ChatGroupBody("test", "test", false, 10L, false, "U297ebe0e5558103f015558d2f89b0508", null);
		ResponseWrapper result = (ResponseWrapper)group.createChatGroup(payload);
		System.out.println(result);*/
		
		//UserNamesBody users = new UserNamesBody(new String[]{"C297ebe0e55580ffb015558cb2980001a"});
		
		//ResponseWrapper result = (ResponseWrapper)group.addBatchUsersToChatGroup("212358643994067368", users);
		//System.out.println(result);
		
		ResponseWrapper result = (ResponseWrapper)group.removeBatchUsersFromChatGroup("212358643994067368", new String[]{"C297ebe0e55580ffb015558cb2980001a"});
		System.out.println(result);
		
		//"ed3953f0-011f-11e6-97af-b36cf9bec662"
		
		/*BodyWrapper userBody = new ModifyNicknameBody("昵称2");
		ResponseWrapper result = (ResponseWrapper)user.modifyIMUserNickNameWithAdminToken("C297ebe0e54c2e89e0154c36c564200aa", userBody);
		System.out.println(result.getResponseStatus());*/
		
		//ResponseWrapper response = user.getIMUsersByUserName("C297ebe0e54c2e89e0154c36c564200aa");
		//ResponseWrapper response = user.deleteIMUserByUserName("C297ebe0e54c2e89e0154c36c564200aa");
		//boolean response = EasemobUtils.createIMUser("C297ebe0e54c2e89e0154c36c564200aa", "000000", "test");
		/*ChatMessageAPI chat = (ChatMessageAPI)factory.newInstance(EasemobRestAPIFactory.MESSAGE_CLASS);
		FileAPI file = (FileAPI)factory.newInstance(EasemobRestAPIFactory.FILE_CLASS);
		SendMessageAPI message = (SendMessageAPI)factory.newInstance(EasemobRestAPIFactory.SEND_MESSAGE_CLASS);
		ChatGroupAPI chatgroup = (ChatGroupAPI)factory.newInstance(EasemobRestAPIFactory.CHATGROUP_CLASS);
		ChatRoomAPI chatroom = (ChatRoomAPI)factory.newInstance(EasemobRestAPIFactory.CHATROOM_CLASS);

        ResponseWrapper fileResponse = (ResponseWrapper) file.uploadFile(new File("d:/logo.png"));
        String uuid = ((ObjectNode) fileResponse.getResponseBody()).get("entities").get(0).get("uuid").asText();
        String shareSecret = ((ObjectNode) fileResponse.getResponseBody()).get("entities").get(0).get("share-secret").asText();
        InputStream in = (InputStream) ((ResponseWrapper) file.downloadFile(uuid, shareSecret, false)).getResponseBody();
        FileOutputStream fos = new FileOutputStream("d:/logo1.png");
        byte[] buffer = new byte[1024];
        int len1 = 0;
        while ((len1 = in.read(buffer)) != -1) {
            fos.write(buffer, 0, len1);
        }
        fos.close();*/

        /*
		// Create a IM user
		BodyWrapper userBody = new IMUserBody("User101", "123456", "HelloWorld");
		user.createNewIMUserSingle(userBody);

		// Create some IM users
		List<IMUserBody> users = new ArrayList<IMUserBody>();
		users.add(new IMUserBody("User002", "123456", null));
		users.add(new IMUserBody("User003", "123456", null));
		BodyWrapper usersBody = new IMUsersBody(users);
		user.createNewIMUserBatch(usersBody);
		
		// Get a IM user
		user.getIMUsersByUserName("User001");
		
		// Get a fake user
		user.getIMUsersByUserName("FakeUser001");
		
		// Get 12 users
		user.getIMUsersBatch(null, null);
		*/
	}

}
